package com.atguigu.day4;


import java.lang.invoke.VarHandle;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;


public class DeadLock {
    private static Object lockA = new Object();
    private static Object lockB = new Object();

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (lockA) {
                System.out.println(Thread.currentThread().getName() + "线程已经持有A锁------->试图获得B锁");
                synchronized (lockB) {
                    System.out.println(Thread.currentThread().getName() + "线程成功获得B锁!");
                }
            }
        }, "T1").start();
        new Thread(() -> {
            synchronized (lockB) {
                System.out.println(Thread.currentThread().getName() + "线程已经持有B锁------->试图获得A锁");
                synchronized (lockA) {
                    System.out.println(Thread.currentThread().getName() + "线程成功获得A锁!");
                }
            }
        }, "T2").start();

    }

}
